package com.example.arithmeticleetcode.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description: 1051. 高度检查器
 * @author: FangZhen
 * @create: 2020-04-30 13:27
 **/
public class Demo11 {

    public static void main(String[] args) {
        int[] heights = {1, 1, 4, 2, 1, 3};//3
        int[] heights1 = {5, 1, 2, 3, 4};//5
        int[] heights2 = {1, 2, 3, 4, 5};//0
        System.out.println(heightChecker(heights));
        System.out.println(heightChecker(heights1));
        System.out.println(heightChecker(heights2));
    }

    public static int heightChecker(int[] heights) {
        List<Integer> list = new ArrayList<>();
        for (int height : heights) {
            list.add(height);
        }
        Arrays.sort(heights);
        int count = 0;
        for (int i = 0, len = heights.length; i < len; i++) {
            if (heights[i] != list.get(i)) {
                count++;
            }
        }
        return count;
    }
}
